<template>
  <div>
    <div ref="echart" class="echart"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  data() {
    return {
      myEchart: null,
    };
  },
  computed: {
    echartOptions() {
      let options = {
        brush: {
          toolbox: ['rect', 'clear'],
        },
        toolbox: {
        feature: {
          dataZoom: {
          },
        }
      },
        dataZoom: {},
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
          },
        },
        xAxis: {
          type: "value",
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            symbolSize: 20,
            data: [
              [10.0, 8.04],
              [8.07, 6.95],
              [13.0, 7.58],
              [9.05, 8.81],
              [11.0, 8.33],
              [14.0, 7.66],
              [13.4, 6.81],
              [10.0, 6.33],
              [14.0, 8.96],
              [12.5, 6.82],
              [9.15, 7.2],
              [11.5, 7.2],
              [3.03, 4.23],
              [12.2, 7.83],
              [2.02, 4.47],
              [1.05, 3.33],
              [4.05, 4.96],
              [6.03, 7.24],
              [12.0, 6.26],
              [12.0, 8.84],
              [7.08, 5.82],
              [5.02, 5.68],
            ],
            type: "scatter",
          },
        ],
      };
      return options;
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      let myEchart = echarts.init(this.$refs.echart);
      myEchart.setOption(this.echartOptions);
      myEchart.on("click", function (params) {
        // 控制台打印数据的名称
        console.log(params);
      });

      myEchart.on("brushEnd", function (params) {
        console.log(params);
      });

      myEchart.on('brushselected', function(params) {
        console.log(params)
      })
    },
  },
};
</script>

<style scoped>
.echart {
  height: 500px;
}
</style>
